

let { length: len } = 'haha';
console.log(len)

var a = 'aaaaaaaaaa'
console.log(a.length)
//es5
console.log(a.indexOf('aaa'))
//es6
let s = 'hello word!';
console.log(s.startsWith('hello'))
console.log(s.endsWith('!')) // true
console.log(s.includes('o')) // true

//repeat

var X = 'x'.repeat(3)
console.log(X)

var bc = 'ab',
  bc1, bc2;
bc1 = bc.padStart(5, 'cd')
bc2 = bc.padEnd(5, '01')
console.log(bc1 + '  ' + bc2)

//模板字符串
const tmpl = addrs => `
   <table>
      ${addrs.map(addr => `
          <tr><td>${addr.first}</td></tr>
          <tr><td>${addr.last}</td></tr>
      `).join('-----------')}
   </table>
`
const data = [
  { first: '<Jane>', last: 'Bond' },
  { first: 'Lars', last: '<Croft>' },
];

console.log(tmpl(data));

function add(...values) {
  let sum = 0;

  for (var val of values) {
    sum += val;
  }

  return sum;
}

add(2, 5, 3) // 10


function push(array, ...items) {
  items.forEach(function (item) {
    array.push(item);
    console.log(item);
  });
}
var arrs = [];
push(arrs, 1, 2, 3)
console.log(arrs)


var obj = {}
obj['a' + 'bc'] = 123;
console.log(obj['abc'])

const proto = {
  x: 'hello',
  // foo: () => console.log(this.x)
  foo() {
    console.log(this.x);
  },
};

const obj2 = {
  x: 'world',
  foo() {
    super.foo();
  }
}

Object.setPrototypeOf(obj2, proto);

obj2.foo() // "world"

console.log(NaN == NaN)
console.log(NaN === NaN)
console.log(Object.is(NaN, NaN),'////////////////////////')


let { keys, values, entries } = Object;

let obj3 = { a: 1, b: 2, c: 3 };
for (let key of keys(obj3)) {
  console.log(key)
}
for (let value of values(obj3)) {
  console.log(value)
}
for (let hash of entries(obj3)) {
  console.log(hash)
  console.log(entries(obj3))
}

let obj4 = { one: 1, two: 2 };
for (let [k, v] of Object.entries(obj4)) {
  console.log(
    `${JSON.stringify(k)}: ${JSON.stringify(v)}`
  );
}
// "one": 1
// "two": 2

const obj5 = { foo: 'bar', baz: 42 };
const map = new Map(Object.entries(obj5));
console.log(map) // Map { foo: "bar", baz: 42 }


const obj6 = {
  toString() {
    return 'abc';
  }
};
const sym = Symbol(obj6);

console.log(sym)

const s3 = new Set();

[2, 3, 5, 4, 5, 2, 2].forEach(x => s3.add(x));

for (let i of s3) {
  console.log(i);
}

const map0 = new Map()
  .set(1, 'a')
  .set(2, 'b')
  .set(3, 'c');
const map2 = new Map(
  [...map0].map(([k, v]) => [k * 2, '_' + v])
);
console.log(map2)
// 产生 Map 结构 {2 => '_a', 4 => '_b', 6 => '_c'}

var person = {
  name: 'lisi'
}
var proxy = new Proxy(person, {
  get: function (target, property) {
    if (property in target) {
      return target[property];
    } else {
      throw new ReferenceError("Property \"" + property + "\" does not exist.")
    }
  }
})
console.log(proxy.name) // "lisi"
// proxy.age // 抛出一个错误


var a = [];
for (var i = 0; i < 10; i++) {
  a[i] = function () {
    console.log(i);
  };
}
a[6](); // 10

var b = [];
for (let i = 0; i < 10; i++) {
  b[i] = function () {
    console.log(i)
  }
}
b[6]();//6

var assss = Array.from({ length: 8 }, (value, index) => index)
console.log(assss)

var kong = [];
console.log(Number(kong), '???')

function getQueryString(url, name) {
  var reg = new RegExp("(\\?|&)" + name + "=([^&]*)(&|$)");
  var r = url.substr(1).match(reg);
  if (r != null) return unescape(r[2]);
  return null;
}

var types = getQueryString('http://local.dev-zuma.com/pay_web/transactionManagement/detail?types=3', 'types')
console.log(types)

var a = 5;
function xxx() {
  var a = 0;
  var ten = function () {
    a = 10;
    return a;
  }
  return ten;
}
var b = xxx();
console.log(b());


var u = [undefined, undefined, 1, '', 'false', false, true, null, 'null'];

var a = u.filter(d => d);
console.log(a)

let next = '5c3c22ed934c941f240b179c'
let pre = '5c46c09b6c9ae156c8200a5a'
let now = '5c4677436c9ae156c8200a57'
console.log(pre > next)
console.log(now < pre)
console.log(now > next)
console.log('ryUVoEvmN' > "Bkca7x_74")
console.log('5c4a770f9129903bb095f0a6' > "5c4a77269129903bb095f0a7")

var arrToString = ['一', '二']
console.log(arrToString.toString());
console.log(arrToString.join(','))


const abcd = [{ name: "May", age: 12, id: 1 }, { name: "Jone", age: 13, id: 5 }, { name: "May", age: 15, id: 6 }]

let result = Object.values(abcd.reduce((m, n) => {
  if (!m[n.name]) {
    m[n.name] = { name: n.name, list: [] }
  }
  m[n.name].list.push(n)
  return m
}, {}))

console.log(result)
function foo(n) {

  function fuc(m) {
    return n * m
  }
  return fuc
}
var f = foo(3)(6)
console.log(f)
const sum = new Function('a', 'b', 'return a + b')
console.log(sum(2, 9))

function fn(x) { 
  fn.value = fn.value || 0;
   fn.value += x * x;
    return fn;
   }
   console.log(fn(1)(2).value)

   
function fn2(x){ 
  let a = x *x;
  
  function fn3(y){
    console.log('f3')
    a += y * y
    fn3.value = a;
    return fn3;
  };
  fn3.value = a;
  return fn3;
  }
  console.log(fn2(2)(1)(2)(3).value)
  console.log(Object.toString(fn2),'////')

  function es6quchong(params) {
    return Array.from(new Set(params))
}
console.log(es6quchong([10,1,1,2,3,4,6,6,6,7]),'quchong')